<?php
require_once 'libraries/utilities/functions.php';
$path = "../ptnhuan-web1/data/films.txt";
$full_path = realpath($path);
$films = mreadFile($path);
$rating = NULL;
$rating1 = NULL;
?>
<form method="POST">
    <input type="text" name="rating" ><br>
    <input type="text" name="rating1" >
    <input type="submit" name="submit" value="Search">
</form>

<?php if (isset($_POST['submit'])): ?>
    <?php $rating = (double) $_POST['rating']; ?>
    <?php $rating1 = (double) $_POST['rating1']; ?>
<?php endif; ?>
<?php foreach ($films as $item): ?>
<?php $item = trim($item);
      if(!empty($item)):?>
   <?php
    $film = explode(";", $item);
    $img = trim($film[1]);
    ?>
  <?php if (isset($_GET['uid'])):?>
        <?php if ((int)$_GET['uid'] == (int)$film[4]):?>                                                          
            <img src = 'public/images/films/<?php echo $img ?>'>
            <?php echo $film[2] ?>
            <?php echo $film[3] ?><br>
            <a href="edit.php?if=<?php echo $film[0]?>">Edit</a>
            <br>
        <?php endif; ?>
    <?php else: ?>
        <?php if (isset($film[2]) || isset($film[3])): ?>
            <?php if (($rating <= (double) $film[3]) && ($rating1 >= (double) $film[3])): ?>
                <img src = 'public/images/films/<?php echo $img ?>'>
                <?php echo $film[2] ?>
                <?php if (!empty($film[3])) echo $film[3] ?>
                <a href="edit.php?if=<?php echo $film[0]?>">Edit</a>
                <br>
            <?php endif; ?>
        <?php endif; ?>
    <?php endif; ?>
  <?php endif; ?>
<?php endforeach; ?>   